<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>菜品增加</title>
<!--1. Bootstrap core CSS -->
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<!--2. Custom styles for this template -->
<link href="css/dashboard.css" rel="stylesheet">
</head>
<body>
<jsp:include page="nav.html"></jsp:include>

	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-3 col-md-2 sidebar">
				<ul class="nav nav-sidebar">
					<li ><a href="addusers.jsp">菜系管理</a></li>
					<li class="active"><a href="FoodServlet?op=queryByPage">菜品管理<span class="sr-only">(current)</span></a></li>
					<li ><a href="addtype.jsp">订单管理</a></li>
					<li ><a href="NewsServlet">用户管理<span class="sr-only">(current)</span></a></li>
					<li><a href="addnews.jsp">管理员管理</a></li>

				</ul>

			</div>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">


				<h2 class="sub-header">菜品增加</h2>

				<div class="row clearfix">
					<div class="col-md-8 column">
					<%=request.getAttribute("msg")==null?"":request.getAttribute("msg") %>
					<!-- 前端的校验，大家要记得完成一下  onsubmit="return fun()"-->
						<form class="form-horizontal" role="form" action="FoodServlet" method="post" enctype="multipart/form-data">
							<div class="form-group">
								<label for="inputEmail3" class="col-sm-2 control-label">菜品名称</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="foodname" name="foodname" required="required"/>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜品图片</label>
								<div class="col-sm-10">
									<input type="file" class="form-control" id="foodimg" name="foodimg" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜品简介</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="foodcontent" name="foodcontent" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜品单价</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="price" name="price" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜品销量</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="sales" name="sales" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">上架时间</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="listtime" name="listtime" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">下架时间</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="offtime" name="offtime" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜系编号</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="fdtypeid" name="fdtypeid" required="required"/>
									<span id="msg"></span>
								</div>
							</div>
							<input type="hidden" name="op" value="add">

							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-10">
									<button type="submit" class="btn btn-default">增加</button>
								</div>
							</div>
						</form>
					</div>
					<div class="col-md-4 column"></div>
				</div>



			</div>
		</div>
	</div>

	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!--3 - js/jquery-2.0.3.js -->
	<script src="js/jquery-2.0.3.js"></script>
	<!--4 - ootstrap.min.js -->
	<script src="dist/js/bootstrap.min.js"></script>
	<script>
	  //标记一下ajaxName函数是否有执行
		var msg = "";

		$(function() {
            //文本框事件 ： 失去焦点
			$("#foodname").blur(function() {
				ajaxName();
			});
		});

		function ajaxName() {

			$.ajax({
				//key:value
				url : "FoodServlet",
				type : "get",
				data : {
					typename : $("#foodname").val(),
					op : "ajaxtypename"
				},
				success : function(data) {
					console.log("data->msg: " + data);
					msg = data;
					$("#msg").html(data);
					//$("#msg")得到页面上额id为msg的哪个span

				},
				dataType : "json"

			});

		}

		function check() {
			//点击增加按钮的时候，都要判断是否有重复的内容(类型重复)
			//1 重复校验和判断
			if (msg == "菜品名称不存在,可以使用") {
				return true;//表单要提交
			} else {
				return false;//2表单不提交
			}

		}
	</script>


</body>
</html>